<?php
class Messages extends CActiveRecord {

    public $toId;
    public $fromId;
    public $message;
    public $sendDate;
    public $isNew;
    public $toDel;
    public $fromDel;
    public $dialogId;
    
    public $users;
    
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function tableName() {
        return 'messages';
    }
    
    public function rules() {
        return array(
            array('message, toId', 'required', 'message'=>'{attribute} не может быть пустым'),
            array('fromId, sendDate, isNew, toDel, fromDel, firstId, users', 'safe')
        );
    }
    
    public function relations() {
        return array(
            'userTo'=>array(self::HAS_ONE, 'User', array('userid'=>'toId')),
            'userFrom'=>array(self::HAS_ONE, 'User', array('userid'=>'fromId')),
        );
    }
    
    public function pagination($limit, $offset) {
        $this->getDbCriteria()->mergeWith(array(
            'offset' => $offset,
            'limit' => $limit,
        ));
        return $this;
    }
}
